export default function pieChart(data: any) {
  let sumNumber = 0

  data.forEach((el: any) => {
    sumNumber += el.value
  })

  const options = {
    color: ['#5c9df1', '#f7b06b'],
    tooltip: {
      trigger: 'item',
      backgroundColor: 'rgba(3,50,86,0.8)',
      textStyle: {
        fontSize: 16,
        color: '#ffffff',
      },
    },
    grid: {
      top: '0%',
      left: '5%',
      bottom: '10%',
      right: '5%',
      containLabel: true,
    },
    legend: {
      //图例形状
      icon: 'roundRect',
      orient: 'vertical',
      top: '2%',
      left: '2%',
      show: true,
      itemWidth: 24,
      itemHeight: 24,
      itemGap: 30,
      data: data.map((el: any) => el.name),
      textStyle: {
        fontSize: 14,
        color: '#666',
      },
    },
    title: [
      {
        text: '存储空间',
        top: '3%',
        textAlign: 'center',
        left: '49.5%',
        textStyle: {
          color: '#526a89',
          fontSize: 30,
          fontWeight: '500',
        },
      },
      {
        text: `{a|${sumNumber}}\n{b|GB}`,
        top: 'center',
        left: 'center',
        textStyle: {
          rich: {
            a: {
              fontSize: 30,
              color: '#526a89',
              fontWeight: '700',
            },
            b: {
              fontSize: 22,
              color: '#96acc8',
              padding: [5, 0, 0, 0],
            },
          },
        },
      },
    ],
    series: [
      {
        type: 'pie',
        radius: ['25%', '60%'],
        center: ['50%', '50%'],
        minAngle: 50,
        startAngle: 20, //起始角度
        labelLine: {
          show: true,
          position: 'outside',
          length: 40,
          length2: 60,
        },
        data: data,
        label: {
          normal: {
            formatter: function (params: any) {
              return `{a|${params.data.name}}\n{b|${params.data.value}GB}`
            },
            rich: {
              a: {
                fontSize: 16,
                color: '#96acc8',
              },
              b: {
                fontSize: 20,
                color: '#526a89',
                fontWeight: '700',
                padding: [8, 0, 0, 0],
              },
            },
          },
        },
        itemStyle: {
          borderColor: '#fff',
          borderWidth: 6,
        },
      },
    ],
  }
  return options
}
